package com.example.testlxr9096;

public class ModbusClientManager {

    private static ModbusClientManager instance;
    private ModbusTCPClient device1;
    private ModbusTCPClient device2;

    public static synchronized ModbusClientManager getInstance() {
        if (instance == null) {
            instance = new ModbusClientManager();
        }
        return instance;
    }

    public void initializeDevices(String ip1, int port1, String ip2, int port2) {
        device1 = new ModbusTCPClient(ip1, port1);
        device2 = new ModbusTCPClient(ip2, port2);
    }

    public ModbusTCPClient getDevice1() {
        return device1;
    }

    public ModbusTCPClient getDevice2() {
        return device2;
    }

    public void disconnectAll() {
        if (device1 != null) device1.disconnect();
        if (device2 != null) device2.disconnect();
    }

}
